// em...引入基本API的所需要的东西吧！
let express = require('express');
let app = express();
const http = require('http');

// 引入homeApi
let homeApi = require('./router/home');

let bodyParser = require('body-parser');
app.use(bodyParser.json()); // support json encoded bodies
app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies

// 主要用于解决跨域问题
app.use(function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept,X-Token");
    next();
});

// 使用引入的homeApi
app.use('/homeApi', homeApi);

// 监听3000端口
let httpServer = http.createServer(app);

const PORT = 3000;
httpServer.listen(PORT, function() {
    console.log('HTTP Server is running on: http://localhost:%s', PORT);
});